package com.physique.tea.Component;


import com.physique.tea.Config.HttpSessionConfig;
import com.physique.tea.Service.DeepSeekService;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.ServerEndpoint;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;

import java.io.IOException;

@Component
@ServerEndpoint(value = "/chat/ai",configurator = HttpSessionConfig.class)
public class AiWebSocket {


    DeepSeekService deepSeekService;

    @Setter
    static ApplicationContext applicationContext;


    @OnOpen
    public void onOpen(){
        deepSeekService = applicationContext.getBean(DeepSeekService.class);
    }

    @OnMessage
    public void onMessage(String message, Session session) throws IOException {
        String call = deepSeekService.call(message);
        session.getBasicRemote().sendText(call);
    }

}
